import { Radio as AntRadio } from 'antd';
import React from 'react';
import { useConfig } from '../ConfigProvider';
import { RadioComponent, RadioProps, RadioGroupProps } from './interface';
import './style.less';

const Radio = ((props: RadioProps) => {
  const { antNative, reverseColor, className, ...restProps } = props;
  const { antNative: globalAntNative } = useConfig();

  if (antNative || globalAntNative) {
    return <AntRadio {...restProps}>{props.children}</AntRadio>;
  }

  return (
    <AntRadio
      className={`${reverseColor ? 'xwd-radio-reverse' : ''} ${className || ''}`}
      {...restProps}
    >
      {props.children}
    </AntRadio>
  );
}) as RadioComponent;

const Group = (props: RadioGroupProps) => {
  const { antNative, children, ...restProps } = props;
  const { antNative: globalAntNative } = useConfig();

  if (antNative || globalAntNative) {
    return <AntRadio.Group {...restProps}>{children}</AntRadio.Group>;
  }

  return <AntRadio.Group {...restProps}>{children}</AntRadio.Group>;
};

const Button = (props: RadioProps) => {
  const { antNative, reverseColor, className, ...restProps } = props;
  const { antNative: globalAntNative } = useConfig();

  if (antNative || globalAntNative) {
    return <AntRadio.Button {...restProps}>{props.children}</AntRadio.Button>;
  }

  return (
    <AntRadio.Button
      className={`${reverseColor ? 'xwd-radio-reverse' : ''} ${className || ''}`}
      {...restProps}
    >
      {props.children}
    </AntRadio.Button>
  );
};

// 确保在导出前设置子组件
Radio.Group = Group;
Radio.Button = Button;

// 导出组件
export { Radio };
export type { RadioProps, RadioGroupProps };
export default Radio; 